package com.firefly.admin.config.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.firefly.admin.common.annotations.annotation.OperationLog;
import com.firefly.admin.common.enums.OperationModuleEnum;
import com.firefly.admin.common.enums.OperationTypeEnum;
import com.firefly.admin.common.vo.Result;
import com.firefly.admin.config.entity.FySystemDictionaryItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.firefly.admin.config.service.FySystemDictionaryItemService;
import com.firefly.admin.config.vo.SystemDictionaryItemQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "系统字典项目接口API")
@RestController
@RequestMapping("/system/dictionary/item")
public class FySystemDictionaryItemController {
    @Autowired
    private FySystemDictionaryItemService fySystemDictionaryItemService;

    /**
     * 分页查询系统字典项目接口
     *
     * @param systemDictionaryItemQueryVo 系统字典项目查询条件
     * @return 字典项目信息列表
     */
    @ApiOperation(value = "分页查询系统字典项目接口", notes = "分页查询系统字典项目接口", httpMethod = "GET")
    @PreAuthorize(value = "hasAuthority('system:dictionary')")
    @GetMapping("/list")
    public Result<Page<FySystemDictionaryItem>> getSystemDictionaryItemList(SystemDictionaryItemQueryVo systemDictionaryItemQueryVo) {
        return fySystemDictionaryItemService.getSystemDictionaryItemList(systemDictionaryItemQueryVo);
    }

    /**
     * 系统字典项目新增接口
     *
     * @param fySystemDictionaryItem 系统字典项目信息
     * @return 新增结果
     */
    @ApiOperation(value = "系统字典项目新增接口", notes = "系统字典项目新增接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.CONFIG_MANAGE, operateType = OperationTypeEnum.SYSTEM_DICTIONARY_ITEM, operateDesc = "系统字典项目新增")
    @PreAuthorize(value = "hasAuthority('system:dictionary:item:add')")
    @PostMapping("/add")
    public Result<FySystemDictionaryItem> add(@RequestBody FySystemDictionaryItem fySystemDictionaryItem) {
        return fySystemDictionaryItemService.add(fySystemDictionaryItem);
    }

    /**
     * 系统字典项目编辑接口
     *
     * @param fySystemDictionaryItem 系统字典项目信息
     * @return 编辑结果
     */
    @ApiOperation(value = "系统字典项目编辑接口", notes = "系统字典项目编辑接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.CONFIG_MANAGE, operateType = OperationTypeEnum.SYSTEM_DICTIONARY_ITEM, operateDesc = "系统字典项目编辑")
    @PreAuthorize(value = "hasAuthority('system:dictionary:item:update')")
    @PostMapping("/update")
    public Result<FySystemDictionaryItem> update(@RequestBody FySystemDictionaryItem fySystemDictionaryItem) {
        return fySystemDictionaryItemService.update(fySystemDictionaryItem);
    }

    /**
     * 系统字典项目删除接口
     *
     * @param itemId 字典项目ID
     * @return 删除结果
     */
    @ApiOperation(value = "系统字典项目删除接口", notes = "系统字典项目删除接口", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", required = true, value = "字典项目ID", paramType = "query", dataType = "Long")
    })
    @OperationLog(module = OperationModuleEnum.CONFIG_MANAGE, operateType = OperationTypeEnum.SYSTEM_DICTIONARY_ITEM, operateDesc = "系统字典项目删除")
    @PreAuthorize(value = "hasAuthority('system:dictionary:item:delete')")
    @PostMapping("/delete")
    public Result<String> delete(Long itemId) {
        return fySystemDictionaryItemService.delete(itemId);
    }

    /**
     * 系统字典项目值校验接口
     *
     * @param itemValue    字典项目值
     * @param itemId       字典项目ID
     * @param dictionaryId 字典ID
     * @return 校验结果
     */
    @ApiOperation(value = "系统字典项目值校验接口", notes = "系统字典项目值校验接口", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemValue", required = true, value = "字典项目值", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemId", required = true, value = "字典项目ID", paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "dictionaryId", required = true, value = "字典ID", paramType = "query", dataType = "Long")
    })
    @GetMapping("/value/check")
    public Result<String> itemValueCheck(String itemValue, Long itemId, Long dictionaryId) {
        return fySystemDictionaryItemService.itemValueCheck(itemValue, itemId, dictionaryId);
    }

    /**
     * 通过字典编码获取字典项目列表接口
     *
     * @param dictionaryCode 字典编码
     * @return 校验结果
     */
    @ApiOperation(value = "通过字典编码获取字典项目列表接口", notes = "通过字典编码获取字典项目列表接口", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictionaryCode", required = true, value = "字典编码", paramType = "query", dataType = "String")
    })
    @GetMapping("/value/list")
    public Result<List<FySystemDictionaryItem>> getDictionaryItemByCode(String dictionaryCode) {
        return fySystemDictionaryItemService.getDictionaryItemByCode(dictionaryCode);
    }
}
